/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package niseeUtility;
import java.net.*;
import java.io.*;
/**
 *
 * @author stussy
 */
public class SMTPSendMail {
    public static String mailServer = "p3smtpout.secureserver.net";
    public static String to = "uow321@googlegroups.com";
    public static String from = "bugs@nisee.co.cc";
 public void sendMail() {
   try {
      Socket s = new Socket(mailServer, 25);
      BufferedReader in = new BufferedReader
          (new InputStreamReader(s.getInputStream(), "8859_1"));
      BufferedWriter out = new BufferedWriter
          (new OutputStreamWriter(s.getOutputStream(), "8859_1"));

      send(in, out, "HELO theWorld");
      // warning : some mail server validate the sender address
      //           in the MAIL FROm command, put your real address here
      send(in, out, "MAIL FROM: <"+from+">");
      send(in, out, "RCPT TO: " + to);
      send(in, out, "DATA");
      send(out, "Subject: Bug reported");
      send(out, "From: Bugs R Us <"+from+">");
      send (out, "\n");
      // message body
      send(out, "Information about exception");
      send(out, "\n.\n");
      send(in, out, "QUIT");
      s.close();
   }
   catch (Exception e) {
      System.out.println("Not able to email");//e.printStackTrace();
   }
 }

 public void send(BufferedReader in, BufferedWriter out, String s) {
   try {
      out.write(s + "\n");
      out.flush();
      System.out.println(s);
      s = in.readLine();
      System.out.println(s);
   }
   catch (Exception e) {
      e.printStackTrace();
   }
 }

 public void send(BufferedWriter out, String s) {
   try {
      out.write(s + "\n");
      out.flush();
      System.out.println(s);
   }
   catch (Exception e) {
      e.printStackTrace();
   }
 }
}

